package com.oxygen.pt.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oxygen.pt.mapper.TreatmentRecordMapper;
import com.oxygen.pt.pojo.dto.TreatmentRecordDTO;
import com.oxygen.pt.pojo.entity.TreatmentRecord;
import com.oxygen.pt.pojo.vo.TreatmentRecordVO;
import com.oxygen.pt.service.TreatmentRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class TreatmentRecordServiceImpl implements TreatmentRecordService {

    private final TreatmentRecordMapper mapper;

    @Override
    public Long save(TreatmentRecordDTO dto) {
        TreatmentRecord record = new TreatmentRecord();
        record.setTreatmentTime(dto.getTreatmentTime());
        record.setChamberNumber(dto.getChamberNumber());
        record.setOperator(dto.getOperator());
        record.setRemark(dto.getRemark());
        record.setPatientId(dto.getPatientId());
        mapper.insertSelective(record);
        return record.getRecordId();
    }

    @Override
    public PageInfo<TreatmentRecordVO> page(Long patientId,
                                            LocalDateTime startTime,
                                            LocalDateTime endTime,
                                            Integer chamberNumber,
                                            String operator,
                                            int pageNum,
                                            int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(
                mapper.pageQuery(patientId, startTime, endTime, chamberNumber, operator)
        );
    }
}